<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <base href="<?php echo base_url() ?>"/>
        <title>乐天！ &raquo; 首页</title>
        <meta name="generator" content="Order 1.0"/>
        <link rel="stylesheet" href="css/style.css" type="text/css"/>
        <link rel="stylesheet" href="jquery-ui/css/ui-lightness/jquery-ui-1.9.0.custom.min.css"/>
        <script src="jquery-ui/js/jquery-1.8.2.js" type="text/javascript" charset="utf-8"></script>
        <script src="jquery-ui/js/jquery-ui-1.9.0.custom.min.js" type="text/javascript" charset="utf-8"></script>
        <script>
            $(function () {
                $("input[name*='time']").datepicker({dateFormat:'yy-mm-dd'});

                var modify_place = null;
                $(".link_mod").click(function () {
                    var win_w = ( $('body').width() - 300) / 2;
                    $("#hidden_form").show().css({ "zIndex":"99999", "background-color":"#FFF"});
                    $("#bgDiv").show();
                    //用于搜索前一个元素
                    modify_place = $(this).prev();
                    $("#cash_time").val($(this).prev().text());
                    return false;
                });

                //判断checkbox是否有效的正则表达式
                function check_enable(check_box) {
                    if (modify_place.text().match(/^(\d{4,4})(-|\/)(\d{1,2})\2(\d{1,2})$/))
                        check_box.attr('hidden', false);
                    else {
                        check_box.attr('hidden', true);
                    }
                }

                //关闭时间选择框
                $(".link_close").click(function () {
                    $("#hidden_form").hide();
                    $("#bgDiv").hide();
                    return false;
                });

                //时间确认
                $("#time_comfirm").click(function () {
                    //把选中的时间赋给原元素
                    modify_place.text($("#cash_time").val());
                    var checkbox = modify_place.parent().parent().find(":checkbox");
                    check_enable(checkbox);
                    $("#hidden_form").hide();
                    $("#bgDiv").hide();
                    return false;
                });

                //退出时间选择框
                $("#time_cancle").click(function () {
                    $("#hidden_form").hide();
                    $("#bgDiv").hide();
                    return false;
                });

                //全选
                $(".quanxuan").click(function () {
                    var tables = document.getElementsByTagName("table");
                    var checkboxs = tables[0].getElementsByTagName("input");
                    if (this.checked) {
                        for (var i = 0; i < checkboxs.length; i++) {
                            if (checkboxs[i].hidden == false)
                                checkboxs[i].checked = true;
                        }
                    }
                    else {
                        for (var i = 0; i < checkboxs.length; i++) {
                            checkboxs[i].checked = false;
                        }
                    }
                })

                //确认更改
                $(".confirm").click(function () {
                    var tables = document.getElementsByTagName("table");
                    var checkboxs = tables[0].getElementsByTagName("input");
                    var data = new Array();
                    for (var i = 0; i < checkboxs.length; i++) {
                        if (checkboxs[i].checked) {
                            data.push(checkboxs[i].value);
                            data.push($(checkboxs[i]).parent().parent().find("span").text());
                        }
                    }
                    if (data.length != 0) {
                        var url = this.name;
                        var turnForm = document.createElement("form");
                        //一定要加入到body中！！
                        document.body.appendChild(turnForm);
                        turnForm.method = 'post';
                        turnForm.action = url;
                        // turnForm.target = '_blank';
                        //创建隐藏表单
                        for (var i = 0; i < data.length; i++) {
                            var newElement = document.createElement("input");
                            newElement.setAttribute("name", i);
                            newElement.setAttribute("type", "hidden");
                            newElement.setAttribute("value", data[i]);
                            turnForm.appendChild(newElement);
                            i++;
                            var newElement = document.createElement("input");
                            newElement.setAttribute("name", i);
                            newElement.setAttribute("type", "hidden");
                            newElement.setAttribute("value", data[i]);
                            turnForm.appendChild(newElement);
                        }
                        turnForm.submit();
                    }
                    else {
                        $('#showup').html('请选择对象！');
                        $('#showup').fadeIn(1000);
                        $('#showup').fadeOut(3000);
                    }
                })
            });
        </script>
        <style>
            .confirm {
                height: 32px;
                font-weight: bold;
                font-size: 12px;
                width: 80px;
                background: #7FA448;
                margin: 0;
                border: none;
                cursor: pointer;
                color: white;
                display: inline;
            }

            .search_bnt {
                height: 32px;
                font-weight: bold;
                font-size: 13px;
                width: 100%;
                background: #7FA448;
                margin: 0;
                border: none;
                cursor: pointer;
                color: white;
            }

            .search_bnt:hover {
                background: #8cb352;
            }

            .confirm:hover {
                background: #8cb352;
            }
        </style>
    </head>
    <body>
        <div id="bgDiv"></div>
        <div id="container">
            <div id="header">
                <div id="header-inner">
                    <h1><span><a href="#">乐天！</a></span></h1>

                    <h2>订单管理系统</h2>

                    <div class="clear"></div>
                    <ul class="sw_menu">
                        <li><a href=<?php echo site_url('login')?>  >首页</a></li>
                        <li><a href=# class="sw_menu_current">管理</a></li>
                        <li><a href=#>筛选</a></li>
                        <?php
                        if ($is_admin)
                            echo '<li><a href=' . site_url('admin') . '>后台</a></li>';
                        ?>
                    </ul>
                </div>
            </div>
            <div id="sidebar">
                <div id="sidebar-inner">
                    <ul>
                        <li>                            <?php
                            if($ret['p1']){
                                echo  '<a  href='.site_url("order/new_order") .'>新建订单</a>';
                            }
                            else{
                               echo  '<a style="color:gray"  href="javascript:void(0)">新建订单</a>';
                            }
                            ?>
                           
                        </li>
                        <li class="select">>
                            <?php
                            if($ret['p2']){
                                echo  '<a  href='.site_url("order/wait_for_pay") .'>待付款订单</a>';
                            }
                            else{
                               echo  '<a style="color:gray"  href="javascript:void(0)">待付款订单</a>';
                            }
                            ?>
                        </li>
                        <li>
                            <?php
                            if($ret['p3']){
                                echo  '<a  href='.site_url("order/wait_for_buy") .'>待购货订单</a>';
                            }
                            else{
                               echo  '<a style="color:gray"  href="javascript:void(0)">待购货订单</a>';
                            }
                            ?>
                        </li>
                        <li>
                            <?php
                            if($ret['p4']){
                                echo  '<a  href='.site_url("order/wait_for_delivery") .'>待发货订单</a>';
                            }
                            else{
                               echo  '<a style="color:gray"  href="javascript:void(0)">待发货订单</a>';
                            }
                            ?>
                        </li>
                        <li>
                        <?php
                            if($ret['p5']){
                                echo  '<a  href='.site_url("order/order_allocation") .'>已发货订单</a>';
                            }
                            else{
                               echo  '<a style="color:gray"  href="javascript:void(0)">已发货订单</a>';
                            }
                            ?>                    
                        </li>
                        <div class="clear"></div>
                    </ul>
                </div>
            </div>
            <div class="clear"></div>
            <div id="content-wrapper" style="position:relative;width:1050px;">
                <div style=" position:absolute;top:20px;left:250px;display: none;line-height:40px;height: 40px;color:white; width:200px;font-size:16px;background:#cc6600;text-align: center;z-index:99;"
                     id='showup'>正在提交订单
                </div>
                <div id="hidden_form"
                     style="border: 5px solid #CCC;background:white;padding:20px;position:fixed;top:50%;left:50%;margin-left: -150px;margin-top: -80px;width:300px;height: 160px;display: none">
                    <div style="border-bottom: 1px solid #EAEAEA;height: 40px;line-height: 40px;color: #333;font-size: 16px;margin-bottom: 20px;">
                        <div style="float:left;display:inline;">入账时间</div>
                        <div><a style="float:right;line-height:20px;padding:10px" href="#" class="link_close"></a></div>
                        <div class="clear"></div>
                        <div style="margin: 10px 10px; padding-left:30px; ">
                            <label>入账时间</label>
                            <input type="text" name="cash_time" id="cash_time" class="validate[custom[number],required]"
                                   value="" size="20"/>
                        </div>
                        <p style="padding-left:40px;">

                            <div style="padding-left:40px;">
                                <input type="submit" class="search_bnt" id="time_comfirm" style="width:80px;margin:0 0px"
                                       value="确认"/>
                                <input type="button" class="search_bnt" id="time_cancle" style="width:80px;margin-left:40px"
                                       value="取消"/>
                            </div>
                        </p>
                    </div>
                </div>
                <div id="content">
                    <div>
                        <div style="float:left;">
                            <h3 id="comments-title">
                                <em>等待银行转账订单</em>
                            </h3>
                        </div>
                        <div style="float:right;">
                            全选
                            <input type="checkbox" name="quanxuan" class="quanxuan"/>
                            <?php
                            $data = array(
                                'name' => site_url("order/wait_for_pay_update/" . $num),
                                'id' => 'button',
                                'value' => '确认入账',
                                'type' => 'button',
                                'class' => 'confirm',
                            );
                            echo form_input($data);
                            ?>
                        </div>
                        <div class="clear"></div>
                    </div>
                    <div class="comment-form">
                        <table>
                            <tr>
                                <th style="width:40px;">勾选</th>
                                <th style="width:86px;">日期</th>
                                <th style="width:75px;">订单号</th>
                                <th style="width:75px;">商品编号</th>
                                <th style="width:134px">图片</th>
                                <th style="width:100px">销售链接</th>
                                <th style="width:80px">颜色/尺寸</th>
                                <th style="width:35px;">数量</th>
                                <th style="width:40px;">单价</th>
                                <th style="width:40px;">金额</th>
                                <th style="width:40px;">运费</th>
                                <th style="width:40px;">总额</th>
                                <th style="width:115px;">客户信息</th>
                                <th style="width:50px">收款方式</th>
                                <th style="width:86px;">入账日期</th>
                            </tr>
                            <?php
                            $pre = -1;
                            $data = array();
                            if (!empty($list)) {
                                foreach ($list as $k => $v) {
                                    if ($pre == $v['id']) {
                                        $data[] = $v;
                                    } else {
                                        if (count($data) != 0) {
                                            echo "<tr>";
                                            echo "<td rowspan='" . count($data) . "'>";
                                            $input_data = array(
                                                "name" => "names",
                                                "id" => "ids",
                                                "value" => $data[0]['id'],
                                                "checked" => 0,
                                                "hidden" => true,
                                            );
                                            echo form_checkbox($input_data);
                                            echo "</td>";
                                            echo "<td rowspan='" . count($data) . "'>" . $data[0]['orderTime'] . "</td>";
                                            echo "<td rowspan='" . count($data) . "'>" . $data[0]['orderNumber'] . "</td>";
                                            echo "<td>" . $data[0]['commodityNumber'] . "</td>";
                                            echo "<td><div style=\"border:1px solid #ffecf1;padding:3px;background-color:#efefef\">
<img src='" . $data[0]['imagePath'] . "'width='126px' height='150px' /></div></td>";
                                            echo "<td><a href='" . $v['link'] . "' target='_blank' >" . $data[0]['link'] . "</a></td>";
                                            echo "<td>" . $data[0]['colorAndSize'] . "</td>";
                                            echo "<td>" . $data[0]['amount'] . "</td>";
                                            echo "<td>" . $data[0]['unitPrice'] . "</td>";
                                            echo "<td>" . $data[0]['money'] . "</td>";
                                            echo "<td rowspan='" . count($data) . "'>" . $data[0]['deliveryMoney'] . "</td>";
                                            echo "<td rowspan='" . count($data) . "'>" . $data[0]['total'] . "</td>";
                                            echo "<td rowspan='" . count($data) . "'>" . $data[0]['clientInfo'] . "</td>";
                                            echo "<td rowspan='" . count($data) . "'>" . $data[0]['paymentMethod'] . "</td>";

                                            echo "<td rowspan='" . count($data) . "' class='time'><span>入账时间</span><a href='#' class='link_mod'></a></td>";
                                            echo "</tr > ";

                                            for ($i = 1; $i < count($data); $i++) {
                                                echo "<tr > ";
                                                echo "<td > " . $data[$i]['commodityNumber'] . "</td > ";
                                                echo "<td ><div style=\"border:1px solid #ffecf1;padding:3px;background-color:#efefef\">
<img src = '" . $data[$i]['imagePath'] . "' width='126px' height='150px' /></div></td > ";
                                                echo "<td ><a href = '" . $v['link'] . "' target = '_blank' > " . $data[$i]['link'] . "</a ></td > ";
                                                echo "<td > " . $data[$i]['colorAndSize'] . "</td > ";
                                                echo "<td > " . $data[$i]['amount'] . "</td > ";
                                                echo "<td > " . $data[$i]['unitPrice'] . "</td > ";
                                                echo "<td > " . $data[$i]['money'] . "</td > ";
                                                echo "</tr >";
                                            }
                                        }
                                        $pre = $v['id'];
                                        $data = array();
                                        $data[] = $v;
                                    }
                                }
                                //最后还剩着没处理的$data数据
                                echo "<tr>";
                                echo "<td rowspan='" . count($data) . "'>";
                                $input_data = array(
                                    "name" => "names",
                                    "id" => "ids",
                                    "value" => $data[0]['id'],
                                    "checked" => 0,
                                    "hidden" => true,
                                );
                                echo form_checkbox($input_data);
                                echo "</td>";
                                echo "<td rowspan='" . count($data) . "'>" . $data[0]['orderTime'] . "</td>";
                                echo "<td rowspan='" . count($data) . "'>" . $data[0]['orderNumber'] . "</td>";
                                echo "<td>" . $data[0]['commodityNumber'] . "</td>";
                                echo "<td><div style=\"border:1px solid #ffecf1;padding:3px;background-color:#efefef\">
<img src='" . $data[0]['imagePath'] . "' width='126px' height='150px' /></div></td>";
                                echo "<td><a href='" . $v['link'] . "' target='_blank' >" . $data[0]['link'] . "</a></td>";
                                echo "<td>" . $data[0]['colorAndSize'] . "</td>";
                                echo "<td>" . $data[0]['amount'] . "</td>";
                                echo "<td>" . $data[0]['unitPrice'] . "</td>";
                                echo "<td>" . $data[0]['money'] . "</td>";
                                echo "<td rowspan='" . count($data) . "'>" . $data[0]['deliveryMoney'] . "</td>";
                                echo "<td rowspan='" . count($data) . "'>" . $data[0]['total'] . "</td>";
                                echo "<td rowspan='" . count($data) . "'>" . $data[0]['clientInfo'] . "</td>";
                                echo "<td rowspan='" . count($data) . "'>" . $data[0]['paymentMethod'] . "</td>";

                                echo "<td rowspan='" . count($data) . "' class='time'><span>入账时间</span><a href='#' class='link_mod'></a></td>";
                                echo "</tr > ";
                                for ($i = 1; $i < count($data); $i++) {
                                    echo "<tr > ";
                                    echo "<td > " . $data[$i]['commodityNumber'] . "</td > ";
                                    echo "<td ><div style=\"border:1px solid #ffecf1;padding:3px;background-color:#efefef\"><img src = '" . $data[$i]['imagePath'] . "' width='126px' height='150px' /></div></td > ";
                                    echo "<td ><a href = '" . $v['link'] . "' target = '_blank' > " . $data[$i]['link'] . "</a ></td > ";
                                    echo "<td > " . $data[$i]['colorAndSize'] . "</td > ";
                                    echo "<td > " . $data[$i]['amount'] . "</td > ";
                                    echo "<td > " . $data[$i]['unitPrice'] . "</td > ";
                                    echo "<td > " . $data[$i]['money'] . "</td > ";
                                    echo "</tr >";
                                }
                            }
                            ?>
                        </table>
                        <div class="clear"></div>
                        <?php echo $this->pagination->create_links(); ?>
                        <div class="clear"></div>
                    </div>
                </div>
            </div>
            <div class="clear"></div>
            <div id="footer">
                <hr/>
                <ul>
                    <li>
                        Powered by <a href=#>Swan 1.3.0</a>
                    </li>
                </ul>
            </div>
        </div>
    </body>
</html>

